new Vue({
    el: '#app',
    mixins: [Save],//组件配置文件，路径/utils/components.js
    data() {
        return {
            dataForm: {},
            childDataForm: [{}],//检测结果
            childDataForm1: [],//附件
            detection_results: [],
            detection_attachment:[],
            traceability_batch:[],
            city: [],//地址
            type:'0',//0:可修改  1:只读
        }
    },
    mounted() {
        /**
         * 组件配置文件中自动执行方法
         * 1.this.init(); //初始化文件
         * 2.this.getData(); //仅修改时执行，根据BOM配置属性查询
         */
        let ls_URL = window.location.href;
        this.type = getQueryObject(ls_URL, "type") || '0';
        this.getList();
    },
    methods: {      
        getList(){
           httpRequest({
                url: '/generalBusiness/generalQueryByTableName',
                data: {
                    Data: 'traceability_batch',
                    Condition: `Row_Status='0'`
                },
                type:'GET'
            }).then(data => {
               this.traceability_batch = data;
            }).catch(xhr => {
                this.$message.error("系统错误，请联系开发者!")
            })
        },

        handlePreview(file) {
            this.$emit("preview", file)
        },
        
        handleExceed() {
            this.$message({
                type: 'warning',
                message: '最大上传数:' + this.limit
            });
        },
        
        async handleChange(file) {
            const { raw } = file;
            const that = this;
            if (this.drag) { //上传文件
                if (!file.name.includes('（上传中）') && !file.name.includes('（磁盘文件名')) {
                    file.name = file.name + "（上传中）";
                }
            } else { //上传图片
                new Compressor(raw, {
                    quality: that.quality / 100,
                    success(file) {
                        const validTypes = ['image/jpeg', 'image/png', 'image/webp']
                        if (!validTypes.includes(file.type)) {
                            that.$message.error({ message: '仅支持 JPG / PNG / WEBP 格式的图片', duration: 1500 });
                            return false
                        } else if (file.size / 1024 / 1024 > 8) {
                            that.$message.error({ message: '图片大小不能超过8MB！', duration: 1500 })
                            return false
                        }
                        that.loading = true;
                        that.$emit('progress', that.loading);
                        const formData = new FormData();
                        formData.append('file', file, file.name);
                        let oFileReader = new FileReader();
                        oFileReader.readAsDataURL(file);
                        oFileReader.onload = function (e) {
                            if (!that.base64) {
                                that.$emit('progress', that.loading);
                                httpRequest({
                                    contentType: 'FILE',
                                    headers: {
                                        "X-File-Name": encodeURIComponent(file.name),
                                        "X-File-Size": file.size,
                                        "X-File-Type": file.type,
                                    },
                                    url: '/generalBusiness/upload-stream',
                                    data: file,
                                    processData: false,//防止将图片二进制转化成字符串
                                }).then(res => {
                                    if (res.status == 'success') {
                                        that.$emit("success", file, res)
                                        that.modelValue = res.fileName;
                                        that.$message.success({ message: '上传成功', duration: 1500 })
                                    } else {
                                        that.$message.error({ message: '上传失败', duration: 1500 })
                                    }
                                }).catch(xhr => {
                                    that.$message.error("系统错误，请联系开发者!")
                                }).finally(() => {
                                    that.loading = false;
                                })
                            } else {
                                that.modelValue = e.target.result;
                                that.loading = false;
                                that.$emit('progress', that.loading);
                            }
                        }
                    },
                    error(err) {
                        console.log(err.message);
                    },
                });
            }
        },

        

    
        
    }
})